package com.woniuxy.profile.controller;

import com.woniuxy.commons.dto.IntegralDto;
import com.woniuxy.commons.entity.Integral;
import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.entity.ResponseEntity;
import com.woniuxy.profile.service.IntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: dengzj
 * @Description:
 * @Date: Created in 15:18 2020/8/1
 */
@RestController
@RequestMapping("/integral")
public class IntegralController {
    @Autowired
    private IntegralService integralService;

    /*
    *@Author: dengzj
    *@Description: 根据uid，查找积分明细
    *@Date: 16:02 2020/8/1
    */
    @RequestMapping("/integral")
    @ResponseBody
    public ResponseEntity<PageBean<Integral>> findIntegralByUid(@RequestBody IntegralDto integralDto){
        String p=integralDto.getP();
        int page=1;
        if (p!=null){
            page=Integer.parseInt(p);
        }
        ResponseEntity<PageBean<Integral>> entity=new ResponseEntity<>();
        PageBean<Integral> integral=integralService.findIntegralByUid(integralDto,page);
        if (integral==null){
            return entity.setCode(301).setMessage("未找到");
        }
        return entity.setCode(200).setMessage("ok").setData(integral);
    }
    /*
    *@Author: dengzj
    *@Description: 积分排行
    *@Date: 16:12 2020/8/1
    */
    @RequestMapping("/rank")
    @ResponseBody
    public ResponseEntity rankIntegral(@RequestBody IntegralDto integralDto){
        ResponseEntity entity=new ResponseEntity<>();
        List<Integral> data=integralService.rankingIntegral(integralDto);
        return entity.setData(data).setCode(200).setMessage("ok");
    }
}
